<?php
/**
 * Created by PhpStorm.
 * User: yhg97p
 * Date: 2016/6/30
 * Time: 16:26
 */
session_start();
include __DIR__ . '/vendor/autoload.php';

use EasyWeChat\Foundation\Application;

$options = [
    'debug' => true,
    'app_id' => 'wx1cd5b8a5438c2130',
    'secret' => 'd65240fc907d1aad8d3386ea60d2726e ',
    'token' => 'w0Q52Arls2S9T2qlsRA215q09q2L9R2z',
    'aes_key' => 'Veg9MEUnmztEYnsJgniStH3ifk8O0RmlBQKzvUuwHXE',
    'log' => [
        'level' => 'debug',
        'file' => __DIR__ . '/log/' . date('Y-m-d') . '.log',
    ],
    'guzzle' => [
        'timeout' => 3.0, // 超时时间（秒）
        'verify' => __DIR__ . '/cert/rootca.pem',
    ],

    'oauth' => [
        'scopes'   => ['snsapi_base'],  //snsapi_base | snsapi_userinfo
        'callback' => 'http://'.$_SERVER['SERVER_NAME'].'/wx/oauth_callback.php',    //回调地址
    ]
];

$app = new Application($options);

$oauth = $app->oauth;

$user = $oauth->user();

$_SESSION['wechat_user'] = $user->toArray();

$targetUrl = "http://".$_SERVER['SERVER_NAME']."/index.php?s=/Home/Share/index.html";

header('location:'. $targetUrl);